<?php
include_only();

if(!empty($request) and $request=='yes' and is_subtitle_owner($user_id, $subtitle_id)=='false')
{
$res = mysql_query("INSERT INTO `teams` (`subtitle_id` ,`user_id` ,`state`)VALUES ('$subtitle_id', '$user_id', '0');");
$sub_info = get_subtitle_info($subtitle_id);
$sub_lang = get_language_by_id($sub_info['language']);
$message[] = "<b>Request sent successfully</b><br><b>subtitle:</b> ".$sub_info['title']."<br><b>language:</b> ".$sub_lang['name'];
}

$all_subtitles = get_subtitles_requests();
//print_r($all_subtitles);

$requests = "
<table style='width:100%' border='0'>
<tr>
<td style='width:20px;text-align: center;'>#</td>
<td style='width:300px;'>subtitle name</td>
<td style='width:100px;text-align: center;'>admin</td>
<td  style='width:75px;text-align: center;'>progress</td>
<td style='width:100px;text-align: center;'>team members</td>
<td style='width:40px;text-align: center;'>join</td>
</tr>
";

for ($i = 0; $i <= count($all_subtitles)-1; $i++) {
$index = $i + 1 ;
$progress = get_subtitle_progress($all_subtitles[$i]['table_name']);
$user_info = get_user_info();
$request_admin_name = get_member_info($all_subtitles[$i]['user_id']);
$request_admin_name = $request_admin_name['username'];
if(empty($user_info['id'])){$user_info['id'] = '';}
$request_user_id =  $user_info['id'];
if(empty($request_user_id)){$request_user_id = '';}
$team_info = get_accepted_team_members($all_subtitles[$i]['id']);
$team_count = count($team_info)+1;
$requests = $requests . "
<tr>
<td style='text-align: center;'>". $index ."</td>
<td style=''>". $all_subtitles[$i]['title'] ."</td>
<td style='text-align: center;'>". $request_admin_name ."</td>
<td style='text-align: center;'>". $progress ."% </td>
<td style='text-align: center;'>". $team_count ."</td>
<td style='text-align: center;'>
<form method='post' action='index.php'>
<input type='image' src='templates/".read_option('theme_folder')."/control/request.png' title='request join team'/>
<input type='hidden' name='page' value='requests' />
<input type='hidden' name='user_id' value='".$request_user_id."' />
<input type='hidden' name='subtitle_id' value='".$all_subtitles[$i]['id']."' />
<input type='hidden' name='request' value='yes' />
</form>
</td>
</tr>";
}

$requests = $requests . "
</table>
";
?>